package com.cloudsigns.factorymanager2.project.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.project.iview.IAddProduceOrderView;
import com.cloudsigns.factorymanager2.project.model.AddProduceOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddProduceOrderModel;

public class AddProduceOrderPresenter {
    private IAddProduceOrderView orderView;
    private IAddProduceOrderModel orderModel;
    private Handler mHandler = new Handler();

    public AddProduceOrderPresenter(IAddProduceOrderView iAddProduceOrderView) {
        this.orderView = iAddProduceOrderView;
        this.orderModel = new AddProduceOrderModel();
    }

    public void addProduceOrder() {

        orderModel.addProduceOrderModel(orderView.getCompleteDate(),
                orderView.getEngineeringName(),
                orderView.getIsHurry(),
                orderView.getLevel(),
                orderView.getProductList(),
                orderView.getProjectName(),
                orderView.getType(),
                new AddProduceOrderModel.OnAddProduceOrderListener() {

                    @Override
                    public void success(final String orderId) {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                orderView.showSuccess(orderId);
                                orderView.hideLoading();
                            }
                        });
                    }

                    @Override
                    public void failed(final String desc) {
                        //需要在UI线程执行
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                orderView.showError(desc);
                                orderView.hideLoading();
                            }
                        });
                    }
                });
    }
}
